﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GSM.BusinessLayer;
using GSM.BusinessLayer.DataLayer;

namespace CRM_SMS_MARKETING.BL
{
    class BLLCustomer
    {
        CustomerSql customersql;
        Customer_MessageSql CMsql;
        Message_Market MMsql;
        BLEvent blEvent;
        PromotionSql promotionsql;
        BLLPromotion bllPromotion;
        EventSql evensql;
        Event_CustomerSql ECsql;
        public BLLCustomer()
        {
            customersql = new CustomerSql();
            CMsql = new Customer_MessageSql();
            blEvent = new BLEvent();
            promotionsql = new PromotionSql();
            bllPromotion = new BLLPromotion();
            evensql = new EventSql();
            ECsql = new Event_CustomerSql();
        }
        public void CustomerBirthDay()
        {
            Event even = blEvent.GetEventByID(1);
            List<Customer> ListCustomer = new List<Customer>();
            ListCustomer = customersql.SelectCustomerByBirthday();
            if (even.EventStatus == true)
            {
                if (ListCustomer.Count != 0)
                {

                    Promotion proVoucher = new Promotion();
                    proVoucher = bllPromotion.GetPromotionByID((int)even.PromotionID);
                    Promotion proGift = new Promotion();
                    proGift = bllPromotion.GetPromotionByID((int)even.PromotionID2);

                    blEvent.CreateSMSForBirthday(even, proVoucher.PromotionSubject, proGift.PromotionSubject, ListCustomer, 1);
                    
                }

            }

        }
        public void CustomerEvent()
        {
            List<Event> ListEvent = new List<Event>();
            ListEvent = evensql.SelectAllOfToday();
            if (ListEvent.Count != 0)
            {
                for (int i = 0; i < ListEvent.Count; i++)
                {
                    if (ListEvent[i].EventStatus == true&&ListEvent[i].EventMessageStatus==false)
                    {
                        //Luu lai la bang nay da generate sms
       
                        List<Customer> ListCustomer = new List<Customer>();

                        //Danh sach Khach Hang cua Event
                        ListCustomer = blEvent.GetListCustomerOfEvent(ListEvent[i].EventID);
                        Promotion proVoucher = new Promotion();
                        proVoucher = bllPromotion.GetPromotionByID((int)ListEvent[i].PromotionID);
                        Promotion proGift = new Promotion();
                        proGift = bllPromotion.GetPromotionByID((int)ListEvent[i].PromotionID2);

                        blEvent.CreateSMSForEvent(ListEvent[i], proVoucher.PromotionSubject, proGift.PromotionSubject, ListCustomer);
                        ListEvent[i].EventMessageStatus = true;
                        evensql.Update(ListEvent[i]);// Co the sua lai la Moi Event Customer Message Status lai 
                    }
                }
            }

        }
        public List<Customer> SelectAll()
        {
            List<Customer> ListCustomer = new List<Customer>();

            return ListCustomer;
        }
    }

}
